/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.ts.repository;

import com.fzhucc.modules.sciPersonnelInfo.domain.SciPersonnelInfo;
import com.fzhucc.modules.ts.domain.TsTeam;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author yyg
 * @website https://eladmin.vip
 * @date 2023-12-07
 **/
public interface TsTeamRepository extends JpaRepository<TsTeam, Integer>, JpaSpecificationExecutor<TsTeam> {

    @Query(nativeQuery = true, value = "select * from tb_ts_team where is_delete=0 and org_area like :area and audit_status=:auditStatus")
    List<TsTeam> findNormalByLikeAreaWithOutIsShow(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_ts_team where is_delete=0 and audit_status=:auditStatus")
    List<TsTeam> findNormalByLikeAreaWithOutIsShowFJS(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_ts_team where is_delete=0 and audit_status=:auditStatus LIMIT 1")
    List<TsTeam> findNormalByLikeAreaWithOutIsShowFJSLimitOne(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_ts_team where is_delete=0 and audit_status=:auditStatus and org_area like:orgArea and is_show=1 and sq_type like:sqType")
    List<TsTeam> findNormalByLikeAreaWithLikeSqType(String auditStatus,String orgArea,String sqType);


    @Query(nativeQuery = true, value = "select * from tb_ts_team where is_delete=0 and (org_area like :area or org_area = :area2)  and audit_status=:auditStatus and is_show=1")
    List<TsTeam> findNormalByLikeAreaWithIsShow(String area, String auditStatus, String area2);


    @Query(nativeQuery = true, value = "select * from tb_ts_team where is_delete=0 and org_area like :area and  org_area != :area2 and  org_area != :area3  and audit_status=:auditStatus and is_show=1")
    List<TsTeam> findNormalByLikeAreaWithIsShow2(String area, String auditStatus, String area2, String area3);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSeven(String area, String auditStatus, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeAreaWithOutIsShowDSeven(String area,String auditStatus,Date dtime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0  and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenFJS(String auditStatus, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0  and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeAreaWithOutIsShowDSevenFJS(String auditStatus,Date dtime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0  and org_area like:area and audit_status=:auditStatus")
    int findCountNormalByLikeArea(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0  and org_area like:area and audit_status=:auditStatus and create_time<=:eTime")
    int findCountNormalByLikeAreaWithTime(String area, String auditStatus, Date eTime);


    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status=:auditStatus and create_time<=:btime and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenCreate(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status=:auditStatus and delete_time<=:btime and delete_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowDSevenDel(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status like:auditStatus and create_time<=:btime and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDsh(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status like:auditStatus and create_time<=:btime ")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDshWithOutS(String area, String auditStatus,  Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_ts_team where is_delete=0 and org_area like :area and audit_status not like:auditStatus and create_time<=:btime ")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDshWithOutSNotLike(String area, String auditStatus,  Date btime);
}